#ifndef _protocol_bms_h_
#define _protocol_bms_h_
/*
note: this part is reference from modbus
sci communication parameter:
speed:9600
checksum:even
stopbit:1
slave add:0x01
*/
typedef struct bms_result_str{
	uint16_t	volt;
	uint16_t	current;
	uint16_t	capacity;
	uint16_t	cab_capacity;
	uint16_t	loop_count;
	uint16_t	date;
	uint16_t	equal_states;
	uint16_t	equal_states_high;
	uint16_t	protect_states;
	uint16_t	soft_version;
	uint8_t		RSOC;
	uint8_t		FET_cont_states;
	uint8_t		batt_seri_count;
	uint8_t		ntc_count;
	uint16_t	ntc_1;
	uint16_t	ntc_2;
	uint16_t	seri_volt[7];
	uint8_t		version[8];
}bms_resultInfo, *bms_PresultInfo;
typedef struct bms_info_str{
	uint8_t  timer;
	uint8_t  count;
	uint8_t  len;
	uint8_t  step;
	uint8_t  lastCmd;
	uint16_t crc16;
	uint16_t crc16_T;
}bms_tinfo,*bms_Pinfo;
extern bms_resultInfo	bms_result;
extern bms_tinfo 		bms_proinfo;

#define 	bms_ID			(1)
#define   	bms_group		(5)
#define 	bms_head		(0xDD)
#define 	bms_tail		(0x77)

extern uint8_t bms_period_callback(void);
/*
note: 
    the u8_bms_idealtimer should be update by timer
*/
extern void bms_rxFunc_callback(uint8_t data_rx);
/*
Cmds
*/
/*
status check:DD A5 03 00 FF FD 77
*/
extern uint8_t bms_basicstatus_Get(void);
/*
Read single volt 
:DD A5 04 00 FF FC 77
*/
extern uint8_t bms_singlevolt_Get(void);
/*
Get hardware version 
:DD A5 05 00 FF FB 77
*/
extern uint8_t bms_hardwareVersion_Get(void);

/*
user can use this function to change low tx function
*/
extern void bms_lowTxfunc_Register(FunType_bufferTx txFunc);
extern void bms_init(FunType_bufferTx txFunc);
/*
this function should be call by application periodly
*/
extern uint8_t bms_task(void);
extern uint8_t bms_interfaceTest(void);

#endif

